/*
day285
2020.6.8
*/
#include<iostream>
using namespace std;
 
struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode* partition(ListNode* head, int x) {
		ListNode* first=new ListNode(0),*last=first;
		ListNode* pre=new ListNode(0),*p=pre;
		
		pre->next=head;
		
		while(p->next)
		{
			if(p->next->val<x)
			{
				ListNode *tem=p->next;
				p->next=p->next->next;
				last->next=tem;
				last=last->next;
			}
			else
			{
				p=p->next;
			}
		}
		last->next=pre->next;
		head=first->next;
		delete(first);
		delete(pre);
		return head;
    }
};

int main()
{
	return 0;
}
